#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 3005;
int n, m, e_cnt;
int heads[N], f[N][N], val[N];

struct Edge {
  int v, nxt, w;
} e[N << 1];

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], e[e_cnt].w = w, heads[u] = e_cnt;
}

int solve(int x) {
  f[x][0] = 0;
  if (x > n - m) return f[x][1] = val[x], 1;
  int siz = 0;
  for (int i = heads[x], v, tmp; i; i = e[i].nxt) {
    siz += tmp = solve(v = e[i].v);
    for (int j = siz; j; --j) {
      for (int k = 1; k <= std::min(j, tmp); ++k)
        f[x][j] = std::max(f[x][j], f[x][j - k] + f[v][k] - e[i].w);
    }
  }
  return siz;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P1273 有线电视网.in", "r", stdin);
  freopen("P1273 有线电视网.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  memset(f, -0x3f, sizeof(f));
  for (int i = 1, k, a, c; i <= n - m; ++i) {
    scanf("%d", &k);
    for (int j = 1; j <= k; ++j) {
      scanf("%d%d", &a, &c);
      add(i, a, c);
    }
  }
  for (int i = n - m + 1; i <= n; ++i) scanf("%d", &val[i]);
  solve(1);
  for (int i = m; ~i; --i) {
    if (f[1][i] >= 0) {
      printf("%d", i);
      break;
    }
  }
  return 0;
}